//改变套餐时刷新内容事件
function changePhonePackage(id, value){
	$.ajax({
		url: "changePhonePackage.jhtml",
		type: "GET",
		data: {packageId:id},
		dataType: "json",
		cache: false,
		async: false,
		success: function(data) {
			//国内语音
			var domesticSpeech = data.phonePackage.domesticSpeech;
			//本地拨打国内语音
			var localSpeech=data.phonePackage.localSpeech;
			//国内流量
			var domesticNetworkFlow=data.phonePackage.domesticNetworkFlow;
			//国内短信
			var domesticShortMessage=data.phonePackage.domesticShortMessage;
			//国内彩信
			var domesticMultimediaMessage=data.phonePackage.domesticMultimediaMessage;
			//免费接听范围
			var freeReceiveScope='';
			if(data.phonePackage.freeReceiveScope == "contry") {
				freeReceiveScope='全国免费';
			}else{
				freeReceiveScope='本地免费';
			}
			//超出部分国内语音费
			var exceedDomesticSpeechFee=data.phonePackage.exceedDomesticSpeechFee;
			//超出部分国内流量费
			var exceedLocalSpeechFee=data.phonePackage.exceedLocalSpeechFee;
			//超出部分国内短信费
			var exceedDomesticNetworkFlowFee=data.phonePackage.exceedDomesticNetworkFlowFee;
			//起出部分短信费
			var exceedDomesticShortMessageFee=data.phonePackage.exceedDomesticShortMessageFee;
			//超出部分彩信费
			var exceedDomesticMultimediaMessageFee=data.phonePackage.exceedDomesticMultimediaMessageFee;
			
			if (!domesticSpeech) {
				domesticSpeech = "";
			}
			
			if (!localSpeech) {
				localSpeech = "";
			}
			
			if (!domesticNetworkFlow) {
				domesticNetworkFlow = "";
			}
			
			if (!domesticShortMessage) {
				domesticShortMessage = "";
			}
			
			if (!domesticMultimediaMessage) {
				domesticMultimediaMessage = "";
			}
			
			if (!freeReceiveScope) {
				freeReceiveScope = "";
			}
			
			if (!exceedDomesticSpeechFee) {
				exceedDomesticSpeechFee = "";
			}
			
			if (!exceedLocalSpeechFee) {
				exceedLocalSpeechFee = "";
			}
			
			if (!exceedDomesticNetworkFlowFee) {
				exceedDomesticNetworkFlowFee = "";
			}
			
			if (!exceedDomesticShortMessageFee) {
				exceedDomesticShortMessageFee = "";
			}
			
			if (!exceedDomesticMultimediaMessageFee) {
				exceedDomesticMultimediaMessageFee = "";
			}
			
			var packageUp=
				'<tr  class="Otr">'+
                	'<td>月费</td>'+
                	'<td>'+ data.phonePackage.monthFee +'元</td>'+
                '</tr>'+
                '<tr  class="Otr">'+
                    '<td>国内语音拨打分钟数</td>'+
                    '<td>'+ domesticSpeech +'分钟</td>'+
                '</tr>'+
                '<tr  class="Otr">'+
                    '<td>国内流量</td>'+
                    '<td>'+ domesticNetworkFlow +'兆</td>'+
                '</tr>'+
                '<tr  class="Otr">'+
                    '<td>国内短信发送条数</td>'+
                    '<td>'+ domesticShortMessage +'条</td>'+
                '</tr>'+
                '<tr  class="Otr">'+
                	'<td>接听</td>'+
                	'<td>'+ freeReceiveScope +'</td>'+
                '</tr>';
			var packageDown=
				'<tr class="Otra">'+
                	'<td>国内语音拨打</td>'+
                	'<td>'+ exceedDomesticSpeechFee +'元</td>'+
                '</tr>'+
                '<tr class="Otra">'+
                	'<td>本地语音拨打</td>'+
                	'<td>'+ exceedLocalSpeechFee +'分钟</td>'+
                '</tr>'+
                '<tr class="Otra">'+
                	'<td>国内流量</td>'+
                	'<td>'+ exceedDomesticNetworkFlowFee +'元/兆</td>'+
                '</tr>';
                if(exceedDomesticShortMessageFee == exceedDomesticMultimediaMessageFee) {
                	packageDown += 
                		'<tr  class="Otra">'+
                        	'<td>短信、彩信</td>'+
                        	'<td>'+ exceedDomesticMultimediaMessageFee +'元/条</td>'+
                        '</tr>';
                }else {
                	packageDown += 
                		'<tr  class="Otra">'+
                        	'<td>短信</td>'+
                        	'<td>'+ exceedDomesticShortMessageFee +'元/条</td>'+
                        '</tr>'+
                        '<tr  class="Otra" >'+
                        	'<td>彩信</td>'+
                        	'<td>'+ exceedDomesticMultimediaMessageFee +'元/条</td>'+
                        '</tr>';
                }
            $("#hidden_packageId").attr("value",id);
            $("#selectedPackage").empty().append("已选择套餐："+ value +"元/月");
			$("#packageUp").empty().append(packageUp);
			$("#packageDown").empty().append(packageDown);
		}
	});
}

//改变存费送费刷新内容的事件
function changeStorage(id) {
	$.ajax({
		url: "changeStorageDeliveryFee.jhtml",
		type: "GET",
		data: {storageId:id},
		dataType: "json",
		cache: false,
		async: false,
		success: function(data) {
			var give = data.storageDeliveryFee.give;
			var monthReturn = data.storageDeliveryFee.monthReturn;
			var contractPeriodType = data.storageDeliveryFee.contractPeriodType;
			if(!give) {
				give = '0';
			}
			if(!monthReturn) {
				monthReturn = '0';
			}
			if(!contractPeriodType) {
				contractPeriodType = '';
			}else if(contractPeriodType == "oneyear"){
				contractPeriodType = '12个月';
			}else {
				contractPeriodType = '24个月';
			}
			
			var storageInfo=
				'<tr class="Otra">'+
                	'<td>赠送金额</td>'+
                	'<td>'+ give +'元</td>'+
                '</tr>'+
                '<tr class="Otra">'+
                	'<td>分月返还</td>'+
                	'<td>'+ monthReturn +'元</td>'+
                '</tr>'+
                '<tr class="Otra">'+
                	'<td>合约期</td>'+
                	'<td>'+ contractPeriodType +'</td>'+
                '</tr>';
			$("#storageInfo").empty().append(storageInfo);
		}
	});
}

//确认套餐事件
function submitPackage() {
	//获取隐藏所选号码
	var selectedPhoneNum = $("#hidden_selectedPhoneNum").val();
	//获取所选套餐id
	var packageId = '';
	$("#packageName li").each(function(idx, item) {
		if($(item).hasClass("on")) {
			packageId = $(item).attr("id");
		}
	});
	//获取云服务id
	var cloudServiceId = '';
	$("#cloud_service").find('input[name="cloudServiceName"]').each(function(idx){
		if(idx == 0) {
			cloudServiceId += $("#hidden_cloudServiceId").val();
		}
	});
	//获取可选包子项id
	var pwis = new Array();
	var i=0;
	$("#packageWrapItems li").each(function(idx, item) {
		if($(item).hasClass("on")) {
			if($(item).attr("id") != "bxz") {
				pwis[i] = $(item).attr("id");
				i++;
			}
		}
	});
	var packageWrapItemIds = pwis.toString();
	//获取存费送费id
	var storageId = '';
	$("#storageLi li").each(function(idx, item){
		if($(item).hasClass("on")) {
			if($(item).html() != "不选择") {
				storageId = $(item).attr("id");
			}
		}
	});
	window.location.href = "submitPackage.jhtml?selectedPhoneNum=" +selectedPhoneNum+ "&phonePackageId=" + packageId + "&cloudServiceId="+ cloudServiceId +"&packageWrapItemIds="+ packageWrapItemIds +"&storageId="+ storageId +"";
}






